<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;



//后台模块表
class UserPaytypeModel extends Model
{
	//定义一个表名
	protected $table = 'user_paytype';
	//定义主键
	protected $primaryKey = 'id';
	protected $guarded = [];


	//添加
	static function do_add($type,$uid,$name,$account,$bank='',$logo='',$logo_bj='',$bank_name='',$pic=''){
		UserPaytypeModel::create([
			'uid' => $uid,
			'name' => $name,
			'account' => $account,
			'type' => $type,
			'bank' => $bank,
			'bank_logo' => $logo,
			'bank_logo_bg' => $logo_bj,
			'bank_name' => $bank_name,
			'pic' => $pic,
		]);
	}

	//查询
	static function list($uid){
		$data = [];
		$list = UserPaytypeModel::where('uid',$uid)->get();
		foreach($list as $k=>$v){
			$data[$k]['id'] = $v['id'];
			$data[$k]['name'] = $v['name'];
			$data[$k]['account'] = $v['account'];
			$data[$k]['bank'] = $v['bank'];
			$data[$k]['bank_logo'] = "http://".$_SERVER['HTTP_HOST'].$v['bank_logo'];
			$data[$k]['bank_logo_bg'] = "http://".$_SERVER['HTTP_HOST'].$v['bank_logo_bg'];
			$data[$k]['bank_name'] = $v['bank_name'];
			$data[$k]['pic'] = $v['pic'];
			$data[$k]['type'] = $v['type'];
			if($v['type'] == 1){
				$data[$k]['typename'] = '银行卡';
			}elseif($v['type'] == 2){
				$data[$k]['typename'] = '微信';
			}else{
				$data[$k]['typename'] = '支付宝';
			}

		}
		return $data;
	}
}